package com.th.supcom.pds.phamapply.client.widget.phamdispense;

import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;

/**
 * InpPhamDispenseDetail主面板.
 * 
 * 住院摆药明细表.
 */
public class InpPhamDispenseDetailMainPanel extends LayoutContainer
{
    private PhamDispenseButtons m_buttons;
    private PhamDispenseFields m_fields;
    private PhamDispenseAction m_ations;
    private PhamDispenseCurrentApplyGrid m_currentApplyGrid;
    private PhamDispenseConditionMain m_dispenseConditionMain;
    private PhamDispenseCollectGrid m_phamDispenseCollectGrid;
    private PhamDispenseDetailGrid m_phamDispenseDetailGrid;
    private PhamDispenseOffsetGrid m_offsetGrid;
    private PhamDispenseNurseUnitInfoGrid m_nurseUnitInfoGrid;
    private PhamDispenseTabPanel m_phamDispenseTabPanel;

    public InpPhamDispenseDetailMainPanel ()
    {
        initUI ();
        initAction ();
        initListeners ();
        initData ();
    }

    /**
     * 初始化事件
     */
    private void initAction ()
    {
        m_ations = new PhamDispenseAction ();
        m_ations.setPhamDispenseFields (m_fields);
        m_ations.setPhamDispenseNurseUnitInfoGrid (m_nurseUnitInfoGrid);
        m_ations.setDispenseDetailGrid (m_phamDispenseDetailGrid);
        m_ations.setCollectGrid (m_phamDispenseCollectGrid);
        m_ations.setCurrentApplyGrid (m_currentApplyGrid);
        m_ations.setDispenseOffsetGrid (m_offsetGrid);
    }

    /**
     * 初始化数据
     */
    private void initData ()
    {
        m_ations.initData ();
    }

    /**
     * 初始化事件监听
     */
    private void initListeners ()
    {
        PhamDispenseListener m_phamDispenseListener;
        m_phamDispenseListener = new PhamDispenseListener ();
        m_phamDispenseListener.setPhamDispenseAction (m_ations);
        m_phamDispenseListener.setPhamDispenseButtons (m_buttons);
        m_phamDispenseListener.setPhamDispenseFields (m_fields);
        m_phamDispenseListener.setDispenseNurseUnitInfoGrid (m_nurseUnitInfoGrid);
        m_phamDispenseListener.initListeners ();
    }

    /**
     * 初始化UI
     */
    private void initUI ()
    {
        this.setLayout (new BorderLayout ());

        createButtons ();
        createFields ();
        createGrids ();
        createPanels ();

        BorderLayoutData centerData = new BorderLayoutData (LayoutRegion.CENTER);
        centerData.setMargins (new Margins (2, 0, 2, 0));
        BorderLayoutData westData = new BorderLayoutData (LayoutRegion.WEST, 200);
        westData.setMargins (new Margins (2, 5, 2, 0));

        add (m_phamDispenseTabPanel, centerData);
        add (m_dispenseConditionMain, westData);
    }

    /**
     * 初始化Buttons
     */
    private void createButtons ()
    {
        m_buttons = new PhamDispenseButtons ();
    }

    /**
     * 初始化Fields
     */
    private void createFields ()
    {
        m_fields = new PhamDispenseFields ();
    }

    /**
     * 初始化Panel
     */
    private void createPanels ()
    {
        m_dispenseConditionMain = new PhamDispenseConditionMain ();
        m_dispenseConditionMain.setPhamDispenseNurseUnitInfoGrid (m_nurseUnitInfoGrid);
        m_dispenseConditionMain.initUI ();

        PhamDispenseOffsetAdjustMainGrid m_offsetAdjustMainGrid;
        m_offsetAdjustMainGrid = new PhamDispenseOffsetAdjustMainGrid ();
        m_offsetAdjustMainGrid.setPhamDispenseOffsetGrid (m_offsetGrid);
        m_offsetAdjustMainGrid.setPhamDispenseCurrentApplyGrid (m_currentApplyGrid);
        m_offsetAdjustMainGrid.initUI ();

        m_phamDispenseTabPanel = new PhamDispenseTabPanel ();
        m_phamDispenseTabPanel.setPhamDispenseOffsetAdjustMainGrid (m_offsetAdjustMainGrid);
        m_phamDispenseTabPanel.setPhamDispenseButtons (m_buttons);
        m_phamDispenseTabPanel.setPhamDisenpseCollectGrid (m_phamDispenseCollectGrid);
        m_phamDispenseTabPanel.setPhamDispenseDetailGrid (m_phamDispenseDetailGrid);
        m_phamDispenseTabPanel.initUI ();
    }

    /**
     * 初始化Grid
     */
    private void createGrids ()
    {
        m_currentApplyGrid = new PhamDispenseCurrentApplyGrid ();
        m_phamDispenseCollectGrid = new PhamDispenseCollectGrid ();
        m_phamDispenseDetailGrid = new PhamDispenseDetailGrid ();
        m_offsetGrid = new PhamDispenseOffsetGrid ();
        m_nurseUnitInfoGrid = new PhamDispenseNurseUnitInfoGrid ();
    }

}